﻿using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;

namespace RHD.Common.Web.Components.AutoComplete {
	public class AutoCompleteBuilder {
		internal int minLength = 3;
		internal IList<SelectListItem> source;
		internal string urlAction;
		internal string fnPrepareParameters;
		internal bool cache = true;

		#region Methods

		public AutoCompleteBuilder MinLength(int i) {
			this.minLength = i;
			return this;
		}

		public AutoCompleteBuilder Source(IEnumerable items, string dataValueField, string dataTextField) {
			this.source = new SelectList(items, dataValueField, dataTextField).ToList();
			return this;
		}

		public AutoCompleteBuilder Source(IList<SelectListItem> items) {
			this.source = items;
			return this;
		}

		public AutoCompleteBuilder LoadDemand(string urlAction, string dataValueField = null, string dataTextField = null) {
			this.urlAction = urlAction;
			return this;
		}

		public AutoCompleteBuilder FnPrepareParameters(string s) {
			this.fnPrepareParameters = s;
			return this;
		}

		public AutoCompleteBuilder Cache(bool b) {
			this.cache = b;
			return this;
		}

		#endregion
	}
}